<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: FacebookController</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">FacebookController</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/app/controllers/facebook_controller_rb.html">
                app/controllers/facebook_controller.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="ApplicationController.html">
                ApplicationController
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000050">friends_get</a>&nbsp;&nbsp;
      <a href="#M000048">index</a>&nbsp;&nbsp;
      <a href="#M000049">start_session</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000050" class="method-detail">
        <a name="M000050"></a>

        <div class="method-heading">
          <a href="#M000050" class="method-signature">
          <span class="method-name">friends_get</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
get a list of friends from facebook and add to logged in user&#8216;s
friends list run from facebook
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000050-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/facebook_controller.rb, line 15</span>
15:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">friends_get</span>
16:     <span class="ruby-keyword kw">begin</span>
17:       <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:facebook_session</span>].<span class="ruby-identifier">init_with_token</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:auth_token</span>])
18:     <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">RBook</span><span class="ruby-operator">::</span><span class="ruby-constant">FacebookSession</span><span class="ruby-operator">::</span><span class="ruby-constant">RemoteException</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
19:       <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:error</span>] = <span class="ruby-node">&quot;An exception occurred while trying to authenticate with Facebook: #{e}&quot;</span>
20:       <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">:controller</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'profile'</span>, <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'show'</span>
21:       <span class="ruby-keyword kw">return</span>
22:     <span class="ruby-keyword kw">end</span>
23:     
24:     <span class="ruby-keyword kw">begin</span>
25:       <span class="ruby-comment cmt">#this is queued up, not taken immediately</span>
26:       <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">:controller</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'profile'</span>, <span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'show'</span>
27:       
28:       <span class="ruby-identifier">uid</span> = <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:facebook_session</span>].<span class="ruby-identifier">session_uid</span>
29:       
30:       <span class="ruby-identifier">current_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>]
31:       
32:       <span class="ruby-comment cmt">#do we want to add &quot;AND is_app_user&quot;?</span>
33:       <span class="ruby-identifier">myResponse</span> = <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:facebook_session</span>].<span class="ruby-identifier">fql_query</span>({<span class="ruby-identifier">:query</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;SELECT first_name, last_name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=#{uid})&quot;</span>})
34:       
35:       (<span class="ruby-identifier">myResponse</span><span class="ruby-operator">/</span><span class="ruby-value str">&quot;//user&quot;</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">user</span><span class="ruby-operator">|</span>
36:         <span class="ruby-identifier">first_name</span> = <span class="ruby-identifier">user</span>.<span class="ruby-identifier">at</span>(<span class="ruby-value str">&quot;first_name&quot;</span>).<span class="ruby-identifier">inner_html</span>
37:         <span class="ruby-identifier">last_name</span> = <span class="ruby-identifier">user</span>.<span class="ruby-identifier">at</span>(<span class="ruby-value str">&quot;last_name&quot;</span>).<span class="ruby-identifier">inner_html</span>
38:         <span class="ruby-identifier">check_friends</span>(<span class="ruby-identifier">current_user</span>, <span class="ruby-identifier">first_name</span>, <span class="ruby-identifier">last_name</span>)
39:       <span class="ruby-keyword kw">end</span>
40:     <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">RBook</span><span class="ruby-operator">::</span><span class="ruby-constant">FacebookSession</span><span class="ruby-operator">::</span><span class="ruby-constant">RemoteException</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
41:       <span class="ruby-identifier">flash</span>[<span class="ruby-identifier">:error</span>] = <span class="ruby-node">&quot;An exception occurred while trying to get friends from Facebook: #{e}&quot;</span>
42:     <span class="ruby-keyword kw">end</span>
43:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000048" class="method-detail">
        <a name="M000048"></a>

        <div class="method-heading">
          <a href="#M000048" class="method-signature">
          <span class="method-name">index</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000048-source">
<pre>
   <span class="ruby-comment cmt"># File app/controllers/facebook_controller.rb, line 3</span>
3:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">index</span>
4:       <span class="ruby-identifier">redirect_to</span>(<span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;start_session&quot;</span>)
5:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000049" class="method-detail">
        <a name="M000049"></a>

        <div class="method-heading">
          <a href="#M000049" class="method-signature">
          <span class="method-name">start_session</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
create a facebook session by prompting the user to login to facebook
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000049-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/facebook_controller.rb, line 8</span>
 8:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start_session</span>
 9:     <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:facebook_session</span>] = <span class="ruby-constant">RBook</span><span class="ruby-operator">::</span><span class="ruby-constant">FacebookWebSession</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'db204644ba402b4d86ac2886372a96bf'</span>, <span class="ruby-value str">'776bfd48e704d1e64f1dcaf24c867bc5'</span>)
10:     <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">session</span>[<span class="ruby-identifier">:facebook_session</span>].<span class="ruby-identifier">get_login_url</span>    
11:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>